﻿// -----------------------------------------------------------------------
// <copyright file="GetLinksByUserIdQuery.cs">
// Copyright (c) 2013 Andrey Veselov. All rights reserved.
// License:  Microsoft Public License (MS-PL)
// Contacts: http://andrey.moveax.com  andrey@moveax.com
// </copyright>
// -----------------------------------------------------------------------

namespace Moveax.DataAccess.Cqrs.Highway.EF.UnitTests.DataAccess.Queries.Links
{
	using System.Collections.Generic;
	using System.Linq;
	using Moveax.DataAccess.Cqrs.Highway.EF.UnitTests.DataAccess.Database.Dto;
	using Moveax.DataAccess.Cqrs.Highway.EF.UnitTests.DataAccess.Mappers;
	using Moveax.DataAccess.Cqrs.Highway.EF.UnitTests.Model.Queries.Links;
	using Moveax.DataAccess.Cqrs.Highway.UnitTests.DataAccess.Queries;
	using Moveax.DataAccess.Cqrs.Highway.UnitTests.Model;

	internal class GetLinksByUserIdQuery : QueryBaseClass, IGetLinksByUserIdQuery
	{
		public GetLinksByUserIdQuery(IDataSource dataSource)
			: base(dataSource)
		{
		}

		public IEnumerable<Link> Execute(int userId)
		{
			var links = this._dataSource.Set<LinkDto>()
				.Where(l => l.UserProfileId == userId)
				.ToList();

			return links.Select(l => l.ToModel()).ToArray();
		}
	}
}